package com.mike.billingserver.controller.v1;

import com.mike.billingserver.constant.ApplicationConstant;
import com.mike.billingserver.entity.BillCategory;
import com.mike.billingserver.service.BillService;
import com.mike.billingserver.vo.HappenedTimeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author xiaozefeng
 * @date 2018-12-18 18:01
 */
@RequestMapping("/")
@Controller
public class IndexController {

    @Autowired
    private BillService billService;

    @GetMapping("/")
    public String index(Model model) {
        List<BillCategory> billCategories = billService.getBillCategories();
        model.addAttribute("categories", billCategories);
        List<HappenedTimeVO> happenedTimes = HappenedTimeVO.generateList();
        model.addAttribute("happenedTimes", happenedTimes);
        model.addAttribute("today", LocalDateTime.now().format(ApplicationConstant.DEFAULT_TIME_FORMATTER));
        return "index";
    }
}
